package com.gzyj.jtt808.v2011.protocol.terminalparam;

import com.gzyj.jtt808.utils.HexBytesUtil;
import io.netty.buffer.ByteBuf;
import lombok.Data;

import java.io.Serializable;
import java.nio.charset.Charset;

/**
 * 主服务器 APN，无线通信拨号访问点。若网络制式为 CDMA，则该处为PPP 拨号号码
 *
 * @author lhj
 */
@Data
public class JTT808_0x8103_0x0010 extends JTT808_0x8103_TerminalParam implements Serializable {

    private String ParamValue;//主服务器 APN，无线通信拨号访问点。若网络制式为 CDMA，则该处为PPP 拨号号码

    public JTT808_0x8103_0x0010() {
        super(0x0010);
    }

    @Override
    public void encode(ByteBuf buf) {
        buf.writeInt(this.getParamId());
        int len=this.ParamValue.getBytes(Charset.forName("GBK")).length;
        buf.writeByte(len);
        buf.writeBytes(HexBytesUtil.WriteStringPadRight(this.ParamValue,len));
    }

    @Override
    public JTT808_0x8103_0x0010 decode(ByteBuf buf) {
        byte[] temp = HexBytesUtil.readByOffset(buf, 4);
        this.setParamId(HexBytesUtil.byteArrayToInt(temp));
        temp = HexBytesUtil.readByOffset(buf, 1);
        this.setParamLength(Byte.toUnsignedInt(temp[0]));
        temp = HexBytesUtil.readByOffset(buf, this.getParamLength());
        this.ParamValue = new String(temp,Charset.forName("GBK"));
        return this;
    }
}